#ifndef CSTATEGAME_H_INCLUDED
#define CSTATEGAME_H_INCLUDED

#include "CState.h"

//class CState;
class CBattle;
class CMinionNode;
class CGUIGame;
class COverlord;
class CAbility;
class RTSCamera;

//! Enumberation for user command when controlling minions
enum MINION_COMMAND
{
  //! Command when either no minion is selected or action is not choosen / cancelled
  CMD_NONE = 0,

  //! Command when "Attack" action is selected
  CMD_ATTACK,

  //! Command when "Move" action is selected
  CMD_MOVE,

  //! Command when a Targeted Ability is used
  CMD_ABILITY

};

class CStateGame : public CState
{
  public:
    //! Constructor
    CStateGame(CGameManager * mgr);

    //! Destructor
    virtual ~CStateGame() {}

    //! State Interface methods
    void init();
    void close();
    void run();
    void enable();
    void disable();

    //! === Events ===
    bool OnKeyUp(EKEY_CODE key);
    bool OnMouseClick();
    bool OnButtonClick(s32 id);
    virtual bool OnGUIEvent(const SEvent& event);
    //! Called when network packets from server arrived
    void OnServerPacketReceived(Packet *packet);

    //! Called when network packets from other clients arrived
    void OnClientPacketReceived(Packet *packet);

    //! === Network Reqs and Acks Messages ===

    //! Attack message
    void reqMinionAttack();
    void ackMinionAttack(BitStream *bs);

    //! Move message
    void reqMinionMove(vector3df intersection);
    void ackMinionMove(BitStream *bs);

    //! Cast Ability message
    void reqMinionSkill(u32 abilityID); // for ABL_NONE
    void reqMinionSkill(u32 abilityID, u32 targetID); // for ABL_TARGET
    void reqMinionSkill(u32 abilityID, vector3df intersection); // for ABL_POINT
    void ackMinionSkill(BitStream *bs);

    //! Create world
    void createWorld(int width, int height);

    //! Called when a new minion gets his turns
    void nextMinion();

    void victoryCheck();

    //! === Commands for input event ==
    void OnCommandAttack();   // attack
    void OnCommandMove();     // defend
    void OnCommandAbility();  // skill / ability

    //! Sets/Gets
    CMinionNode * getSelectedMinion();
    CMinionNode * getPointedMinion();

    void setBattle(CBattle* battle);
    CBattle * getBattle();
    CGUIGame * getGUI() { return gui; }
    ITerrainSceneNode* getTerrain() { return terrain; }
    ISceneNode * getMinionRoot() { return minionRoot; }

    //! Command action after received network packets
    void attack(u32 targetID);
    void moveMinion(vector3df target);
    void ability(u32 abilityID);
    void ability(u32 abilityID, u32 targetID);
    void ability(u32 abilityID, vector3df target);

    void drawFloatingText(vector3df location, stringw text, SColor textColor);

  private:
    RTSCamera* camera;

    CGUIGame * gui;
    ITriangleSelector* selector;
    ITerrainSceneNode* terrain;

    ITextSceneNode * dmgDisplay;

    IMeshSceneNode * pointer;

    ISceneNode *minionRoot;

    // Game Objects
    u16 playerID;

    MINION_COMMAND command;

    CMinionNode * pointed;

    // Ability
    CAbility * ablCurrent;
    CAbility * ablBolt;
    CAbility * ablHeal;
    CAbility * ablBlast;

    CBattle *battle;

    enum BUTTON_ID
    {
      BTN_ATTACK,
      BTN_MOVE,
      BTN_CANCEL,
      BTN_SPELL,
      BTN_ABILITY_1,
      BTN_ABILITY_2,
      BTN_ABILITY_3,
      BTN_POPSTATE,

    };
};



#endif // CSTATEGAME_H_INCLUDED
